﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using App.Interface;
using App.Model;
using Newtonsoft.Json;

namespace App.MVC.Controllers
{
    public class JiaoZhiGongConfigController : BaseController
    {
        public IJiaoZhiGong _IJiaoZhiGong { set; get; }
        public IKeShi _IKeShi { set; get; }
        // GET: JiaoZhiGongCOnfig
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// bc
        /// </summary>
        /// <param name="model"></param>
        public void Save(JiaoZhiGong model)
        {
            if (model.zgid == 0)
            {
                _IJiaoZhiGong.AddEmployee(model.username, model.XingMing, model.ShouJiHao, model.XingBie, model.keshi.ksid, model.zwid);
            }
            else
            {
                _IJiaoZhiGong.UpdateEmployee(model.userinfoId, model.XingMing, model.ShouJiHao, model.XingBie, model.keshi.ksid, model.zwid);
            }
        }
        [HttpPost]
        public void ResetPassword(string username)
        {
            _IJiaoZhiGong.ResetPassword(username);
        }
        /// <summary>
        /// sc
        /// </summary>
        /// <param name="userid"></param>
        public void Del(string userid)
        {
            _IJiaoZhiGong.DelEmployee(userid);
        }

        public JsonResult Gets(string keyword, int ksid, int zwid, int pageIndex, int pageSize)
        {
            string str = _IJiaoZhiGong.GetEmployees(keyword, ksid, zwid, pageIndex, pageSize);
            JiaoZhiGongList tt = new JiaoZhiGongList();

            if (!string.IsNullOrWhiteSpace(str))
            {
                tt = JsonConvert.DeserializeObject<JiaoZhiGongList>(str);
            }
            return Json(tt, JsonRequestBehavior.AllowGet);
        }

        public JsonResult Get(string userid)
        {
            string str = _IJiaoZhiGong.GetEmployee(userid);
            JiaoZhiGong tt = JsonConvert.DeserializeObject<JiaoZhiGong>(str);
            return Json(tt, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetKeShiList()
        {
            string str = _IKeShi.GetAllKeShiList();
            List<KeShi> tt = JsonConvert.DeserializeObject<List<KeShi>>(str);
            return Json(tt, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetKeShiZhiWuOption(int ksid)
        {
            string str = _IKeShi.GetKeShiZhiWuOption(ksid);
            List<ZhiWu> tt = JsonConvert.DeserializeObject<List<ZhiWu>>(str);
            return Json(tt, JsonRequestBehavior.AllowGet);
        }

    }
}